package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 *
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {


    @Autowired
    private TbBusinessMapper tbBusinessMapper;

    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;


    @Override
    @Transactional
    public void add(BusinessTrackVo businessTrackVo) {
        // 1.保存商机基本信息
        TbBusiness tbBusiness = new TbBusiness();
        tbBusiness.setId(businessTrackVo.getBusinessId());
        tbBusiness.setName(businessTrackVo.getName());
        tbBusiness.setPhone(businessTrackVo.getPhone());
        tbBusiness.setOccupation(businessTrackVo.getOccupation());
        tbBusiness.setEducation(businessTrackVo.getEducation());
        tbBusiness.setProvinces(businessTrackVo.getProvinces());
        tbBusiness.setCity(businessTrackVo.getCity());
        tbBusiness.setWeixin(businessTrackVo.getWeixin());
        tbBusiness.setAge(businessTrackVo.getAge());
        tbBusiness.setMajor(businessTrackVo.getMajor());
        tbBusiness.setJob(businessTrackVo.getJob());
        tbBusiness.setSalary(businessTrackVo.getSalary());
        tbBusiness.setQq(businessTrackVo.getQq());
        tbBusiness.setSex(businessTrackVo.getSex());
        tbBusiness.setExpectedSalary(businessTrackVo.getExpectedSalary());
        tbBusiness.setCreateTime(new Date());
        tbBusiness.setCreateBy(SecurityUtils.getUsername());
        tbBusiness.setLevel(businessTrackVo.getLevel());
        tbBusiness.setSubject(businessTrackVo.getSubject());
        tbBusiness.setReasons(businessTrackVo.getReasons());
        tbBusiness.setPlan(businessTrackVo.getPlan());
        tbBusiness.setPlanTime(businessTrackVo.getPlanTime());
        tbBusiness.setCourseId(businessTrackVo.getCourseId());
        tbBusiness.setOtherIntention(businessTrackVo.getOtherIntention());

        tbBusinessMapper.updateTbBusiness(tbBusiness);

        // 2.保存商机跟进信息
        TbBusinessTrackRecord trackRecord = new TbBusinessTrackRecord();
        trackRecord.setBusinessId(businessTrackVo.getBusinessId());
        trackRecord.setTrackStatus(businessTrackVo.getTrackStatus());
        trackRecord.setNextTime(businessTrackVo.getNextTime());
        trackRecord.setKeyItems(businessTrackVo.getKeyItems());
        trackRecord.setRecord(businessTrackVo.getRecord());
        trackRecord.setCreateBy(SecurityUtils.getUsername());
        trackRecord.setCreateTime(new Date());
        tbBusinessTrackRecordMapper.add(trackRecord);
    }

    @Override
    public List<TbBusinessTrackRecord> select(Long id) {
        return tbBusinessTrackRecordMapper.select(id);
    }
}
